﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using iTextSharp.text.pdf;
using System.IO;
using System.Diagnostics;

namespace ExpenseIt
{
    /// <summary>
    /// Interaction logic for offlineDetailPage.xaml
    /// </summary>
    public partial class caseMngHomeVisitReport : Page
    {
        public caseMngHomeVisitReport()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var pathOfExe = System.AppDomain.CurrentDomain.BaseDirectory;
            var relativeToExe = pathOfExe + "SWMPDD_Case_Management_Home_Visit_Note_V.2.03_Extended.pdf";
            PdfReader reader = new PdfReader(relativeToExe);
            reader.RemoveUsageRights();
            try
            {
                PdfStamper stamper = new PdfStamper(reader, new FileStream(@pathOfExe + "filled.pdf", FileMode.Create), '\0', true);
                AcroFields form = stamper.AcroFields;
                //   form.SetField("LSW", LSW.Text);
                //   form.SetField("Text3[1]", "Yes");
                //form.SetField("Client_Appearance", "2");
                foreach (RadioButton radiobutton in caseMngHomeVisitNote.Children.OfType<RadioButton>().Where(rb => rb.IsChecked == true))
                {
                    string radbtn = radiobutton.GroupName;
                    char id = radiobutton.Name[radiobutton.Name.Length - 1];
                    form.SetField(radbtn, id.ToString());
                }
                foreach (TextBox textbox in caseMngHomeVisitNote.Children.OfType<TextBox>())
                {
                    string txtBx = textbox.Name;
                    form.SetField(txtBx, textbox.Text);
                }
                foreach (CheckBox checkbox in caseMngHomeVisitNote.Children.OfType<CheckBox>().Where(cb => cb.IsChecked == true))
                {
                    string CckBx = checkbox.Name;
                    form.SetField(CckBx, "1");
                }
                stamper.Close();
                System.Diagnostics.Process.Start(@pathOfExe + "filled.pdf");
            
            }
            catch (Exception ex)
            {

            }
        }
        private void MenuItemHVF(object sender, RoutedEventArgs e)
        {
            caseMngHomeVisitReport CMHVRPage = new caseMngHomeVisitReport();
            this.NavigationService.Navigate(CMHVRPage);
        }
        private void MenuItemPOC(object sender, RoutedEventArgs e)
        {
            planOfCare POCPage = new planOfCare();
            this.NavigationService.Navigate(POCPage);
        }
    }
}
